#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
	char buffer[256];
	FILE *fp = fopen("./redis.conf", "a+");
	if (fp == NULL) {
		return -1;	
	}
	
	struct stat m_stat;
	lstat("./redis.conf", &m_stat);
	char *fileBuffer = (char *)malloc((unsigned int)((m_stat.st_size * 3) /2));
	printf("%d\n", (unsigned int)((m_stat.st_size * 3) /2));

	FILE *fp_ = fopen("./redis.conf.tmp", "a+");
	if (fp_== NULL) {
		return -1;	//	-5
	}
	
	memset(buffer, 0, 256);
	char *p;
	int j = 0;
	while (fgets(buffer, 256, fp)) {
	//while (fread(buffer, 1, sizeof(buffer), fp) > 0 ) {
		p = buffer;
		while((j = fwrite(p, 1, strlen(p), fp_))) {
			p += j;
		}
		memset(buffer, 0, 256);
	}
	fclose(fp);
	fclose(fp_);
	unlink("./redis.conf");
	rename("./redis.conf.tmp", "./redis.conf");
	chmod("./redis.conf", 0775);

    return 0;
}
